package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.User_Examdetails_Info;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface User_ExamdetailsMapper {
    @Select("SELECT * FROM user_exam_details WHERE exam_id = #{examId}")
    List<User_Examdetails_Info> selectByExamId(@Param("examId") int examId);

    @Select("SELECT * FROM user_exam_details WHERE detail_id = #{detailId}")
    User_Examdetails_Info selectById(@Param("detailId") int detailId);

    @Insert("INSERT INTO user_exam_details (exam_id, question_id, is_correct, user_answer) " +
            "VALUES (#{examId}, #{questionId}, #{isCorrect}, #{userAnswer})")
    @Options(useGeneratedKeys = true, keyProperty = "detailId")
    int insertDetail(User_Examdetails_Info detail);

    @Select("SELECT * FROM user_exam_details WHERE exam_id = #{examId} AND question_id = #{questionId}")
    User_Examdetails_Info selectByExamAndQuestion(@Param("examId") int examId,
                                                  @Param("questionId") int questionId);
}